﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace haber
{
    public partial class Default3 : System.Web.UI.Page
    {

        public static string GetSiteRoot()
        {
            string port = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
            if (port == null || port == "80" || port == "443")
                port = "";
            else
                port = ":" + port;

            string protocol = System.Web.HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
            if (protocol == null || protocol == "0")
                protocol = "http://";
            else
                protocol = "https://";

            string sOut = protocol + System.Web.HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port + System.Web.HttpContext.Current.Request.ApplicationPath;

            if (sOut.EndsWith("/"))
            {
                sOut = sOut.Substring(0, sOut.Length - 1);
            }

            return sOut;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["hid"] != null)
            {
                int hi = -1;
                if( int.TryParse(Request["hid"],out hi)  ){
                
                    using (dcHaberDataContext dc = new dcHaberDataContext())
	                {
                        var baslik = from b in dc.Habers
                                     where b.HaberID == hi
                                     select b;
                        if (baslik.Count() > 0)
                        {
                            Haber h = baslik.First();
                            Page p = this.Page;
                            p.Header.Description = h.Baslik;
                            HtmlMeta hm;
                            hm = new HtmlMeta();
                            hm.Name = "og:title";
                            hm.Content = h.Baslik ;
                            Page.Header.Controls.AddAt(0, hm);


                            hm = new HtmlMeta();
                            hm.Name = "og:type";
                            hm.Content = "website";
                            Page.Header.Controls.AddAt(0, hm);

                            hm = new HtmlMeta();
                            hm.Name = "og:url";
                            hm.Content = GetSiteRoot()+"?hid="+h.HaberID;
                            Page.Header.Controls.AddAt(0, hm);

                            hm = new HtmlMeta();
                            hm.Name = "og:image";
                            hm.Content = GetSiteRoot() + "/HaberResmi/" + h.HaberID+"/"+h.HaberResim;
                            Page.Header.Controls.AddAt(0, hm);


                            hm = new HtmlMeta();
                            hm.Name = "og:site_name";
                            hm.Content = "sosyalmedyahaber.org";
                            Page.Header.Controls.AddAt(0, hm);

                             hm = new HtmlMeta();
                             hm.Name = "fb:admins";
                             hm.Content = "689431045";
                            Page.Header.Controls.AddAt(0, hm);

                        }
	                }
                    
                 
             } 
          }else if(Request["tv"] != null ){

              String isim = Request["tv"].ToString();
              Page p = this.Page;
              p.Header.Description = isim;
              HtmlMeta hm;
              hm = new HtmlMeta();
              hm.Name = "og:title";
              hm.Content = isim;
              Page.Header.Controls.AddAt(0, hm);


              hm = new HtmlMeta();
              hm.Name = "og:type";
              hm.Content = "website";
              Page.Header.Controls.AddAt(0, hm);
              
              
              hm = new HtmlMeta();
              hm.Name = "og:video";
              hm.Content = GetSiteRoot() + "/haberTV/"+isim;
              Page.Header.Controls.AddAt(0, hm);
              string cont= "";
              if (isim.Contains("flv"))
              {
                  cont = "application/x-shockwave-flash";

              }
              else
              {
                  cont = "video/mp4";
              }

              hm = new HtmlMeta();
              hm.Name = "og:video:type";
              hm.Content = cont;
              Page.Header.Controls.AddAt(0, hm);

              hm = new HtmlMeta();
              hm.Name = "og:url";
              hm.Content = GetSiteRoot() + "?tv=" + isim;
              Page.Header.Controls.AddAt(0, hm);

              hm = new HtmlMeta();
              hm.Name = "og:image";
              hm.Content = GetSiteRoot() + "/Styles/default.png";
              Page.Header.Controls.AddAt(0, hm);


              hm = new HtmlMeta();
              hm.Name = "og:site_name";
              hm.Content = "sosyalmedyahaber.org";
              Page.Header.Controls.AddAt(0, hm);

              hm = new HtmlMeta();
              hm.Name = "fb:admins";
              hm.Content = "689431045";
              Page.Header.Controls.AddAt(0, hm);

            }
            

        }
    }
}